﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using DAO_ADMIN;

namespace PTTK19.GUI
{
    class DBPhieuYeuCau
    {

        internal static bool GuiYeuCau(int LoaiPhieu, List<System.Drawing.Point> _dschitiet)
        {
            bool kq = false;
            int id = 0;
            try
            {
                List<SqlParameter> parr = new List<SqlParameter>();
                string procname = "sp_LapPhieuYCMoi";
                parr.Add(new SqlParameter("@MaLoai", LoaiPhieu));
                id = DataProvider.SingleINTOutput(procname, parr);


                procname = "sp_ThemChiTietPhieuYeuCau";
                foreach (Point item in _dschitiet)
                {
                    parr = new List<SqlParameter>();
                    parr.Add(new SqlParameter("@MaPhieu", id));
                    parr.Add(new SqlParameter("@MaSP", item.X));
                    parr.Add(new SqlParameter("@Soluong", item.Y));
                    DataProvider.NonqueryProc(procname, parr);
                }
                kq = true;
            }
            catch (Exception)
            {
                List<SqlParameter> parr = new List<SqlParameter>();
                string procname = "sp_XoaPhieuYC";
                parr.Add(new SqlParameter("@MaPhieu", id));
                DataProvider.NonqueryProc(procname, parr);
                kq = true;
            }
            return kq;
        }
    }
}
